<form action="/management/admin_corporation.php" method="post" name="listform">
<input type="hidden" name="method" value="">
<input type="hidden" name="p" value="{{$curPage}}">
<table width="100%" class="search">
<tr>
	<td class="title">企业ID：</td>
	<td><input type="text" name="cor_id" style="width:70px;" value="{{$smarty.post.cor_id}}"></td>
	<td class="title">企业名称：</td>
	<td><input type="text" name="cor_name" style="width:70px;" value="{{$smarty.post.cor_name}}"></td>
	<td class="title">创建者登录ID：</td>
	<td><input type="text" name="user_id" style="width:70px;" value="{{$smarty.post.user_id}}"></td>
	<td class="title">创建者名字：</td>
	<td><input type="text" name="user_name" style="width:70px;" value="{{$smarty.post.user_name}}"></td>
</tr>
<tr>
	<td class="title">创建时间：</td>
	<td colspan="3"><input type="text" name="time_1" style="width:80px;" onClick="WdatePicker()" value="{{$smarty.post.time_1}}">-<input type="text" name="time_2" style="width:80px;" onClick="WdatePicker()" value="{{$smarty.post.time_2}}"></td>
	<td colspan="4" align="center"><input type="submit" class="button" value="搜索"></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="4" cellspacing="0" class="list">
	<tr>
		<th width="5%">全选<input type="checkbox" onclick="checkAll(this)" id="checkall"></th>
		<th width="5%">ID</th>
		<th width="25%">企业名称</th>
		<th width="25%">企业地址</th>
		<th width="10%">创建者</th>
		<th width="15%">所属分类</th>
		<th width="10%">创建时间</th>
		<th width="5%"></th>
	</tr>
	{{foreach from=$row key=key item=item name="cor"}}
	<tr {{if $smarty.foreach.cor.index%2 eq '0'}}class="even"{{/if}}>
		<td align="center"><input type="checkbox" value="{{$item.id}}" name="selectId[]" onclick="checkOne()"></td>
		<td align="center">{{$item.id}}</td>
		<td align="center"><a target="_blank" href="{{$host_root}}/corporation/{{$item.id}}.html">{{$item.name}}</a></td>
		<td align="center">{{$item.address}}</td>
		<td align="center">{{$item.create_author}}</td>
		<td align="center"><font id="cate_{{$item.id}}">{{$item.ccname}}</font><input type="button" value="修改" class="catebtn" name="{{$item.ccid}}" id="{{$item.id}}"></td>
		<td align="center">{{$item.create_time|date_format:"%Y-%m-%d"}}</td>
		<td align="center">{{if $item.del_flg eq '0'}}<input type="button" value="删除" class="delbtn" onclick="my_del('{{$smarty.server.PHP_SELF}}',{{$item.id}},this)">{{else}}已删除{{/if}}</td>
	</tr>
	{{/foreach}}
</table>
</form>
<div class="operation">
	<ul>
		<li><input type="button" value="批量删除" onclick="delAll();" style="cursor:pointer;"></li>
		<li><input type="button" value="永久删除" onclick="delCompletely();" style="background-color:red;cursor:pointer;"></li>
	</ul>
	<div style="clear:both;"></div>
</div>
<div class="fenye">{{$pageList}}</div>
<div id="bg" class="bg" style="display:none;"></div>
<div id="pop" class="pop" style="display:none;">
	<ul>
		<li style="background-color:#330000; color: white; font-weight: bold;"><span><image id="popclose" src="/images/close.gif" title="关闭" style="width:30px;height:30px;cursor:pointer;"></span>快速修改</li>
		<input type="hidden" id="popid">
		<li id="popcate"></li>
		<li>
			<input class="btn" type="button" value="保存" onclick="popsubmit()">
		</li>
	</ul>
</div>
<script type="text/javascript">
var cateSubCae = new Array();
{{foreach from=$cateSubCae key=key item=item name=cate}}
cateSubCae[{{$smarty.foreach.cate.index}}] = {'ccid':'{{$key}}','ccname':'{{$item}}'};
{{/foreach}}
function delAll()
{
	var checked_objs = $("input[name='selectId[]']:checked");
	if(checked_objs.length < 1){
		alert("至少选择一项");
		return false;
	}
	if(!confirm("确认删除吗？"))return false;
	document.listform.method.value = 'delAll';
	document.listform.submit();
}
function delCompletely()
{
	var checked_objs = $("input[name='selectId[]']:checked");
	if(checked_objs.length < 1){
		alert("至少选择一项");
		return false;
	}
	if(!confirm("确认永久删除吗？删除后数据将无法恢复！"))return false;
	document.listform.method.value = 'delCompletely';
	document.listform.submit();
}
function popHide(){
	$(".pop").hide();
	$(".bg").hide();
}

function popShow(value,id,e){
	showchechbox(value);
	$("#popid").val(id);
	center($(".pop"), $(".bg"), e);
}

function popsubmit(){
	var checkobjs = $("input[name='ccid[]']:checked");
	if(checkobjs.length < 1){
		alert("请至少选择一个分类！");return false;
	}else{
		var ccids = '';
		for(var i=0; i<checkobjs.length; i++){
			ccids += checkobjs[i].value+',';
		}
		ccids = ccids.substr(0,ccids.length-1);
		id = $("#popid").val();
		$.ajax({
			type:"POST",
			url:"admin_corporation.php",
			data:{method:"changeCate",id:id,ccids:ccids},
			success:function(msg){
				var temp = msg.split("@@");
				$("#cate_"+temp[0]).html(temp[1]);
				popHide();
			}            
		});
	}
}

function showchechbox(cateids){
	var temp = cateids.split(",");
	var checkbox = "";
	for(var i=0; i<cateSubCae.length; i++){
		var checked = "";
		for(var j=0; j<temp.length; j++){
			if(temp[j] == cateSubCae[i].ccid){
				var checked = "checked";
			}
		}
		checkbox += '<input '+checked+' type="checkbox" name="ccid[]" value="'+cateSubCae[i].ccid+'">'+cateSubCae[i].ccname;
	}
	$("#popcate").html(checkbox);
}
$(document).ready(function(){
	$(".catebtn").each(function(){
		$(this).click(function(e){
			popShow($(this).attr("name"),$(this).attr("id"),e);
		})
	})
	$("#popclose").click(function(){
		popHide();
	})
})
</script>